//
// Created by yephiu on 2023/7/6.
//

#ifndef FLIGHT_CLION_NIZHOU_DRV_TOF_H
#define FLIGHT_CLION_NIZHOU_DRV_TOF_H

#include "stm32f4xx_hal.h"

typedef struct
{
    uint8_t byte[3];
}TOF_int24_t;

/*TOFSense/TOFSense-P/PS/F/FP等型号的解包数据结构体*/
typedef struct {
    uint8_t ID;

    float dis;					//解包后的距离数据
    uint8_t status;				//解包后的信号状态指示
    uint16_t signal_strength;	//解包后的信号强度
}Tofsense;


typedef struct
{
    uint8_t frame_header;
    uint8_t function_mark;
    uint8_t reserverd;//保留位
    uint8_t ID;//ID
    uint32_t system_time;//系统时间
    TOF_int24_t disatance;//距离(cm)
    uint8_t dis_status;//状态
    uint16_t signal_strength;//信号强度
    uint8_t range_precision;//准确度
    uint8_t checksum;
}TOF_DataPacket;


typedef enum
{
    TOF_WAIT_HEADER,
    TOF_WAIT_FUNCTION_MARK,
    TOF_WAIT_RSERVERD,
    TOF_WAIT_ID,
    TOF_WAIT_SYSTIME,
    TOF_WAIT_DIS,
    TOF_WAIT_DIS_STA,
    TOF_WAIT_SIGNAL_STRENGTH,
    TOF_WAIT_PRECISION,
    TOF_WAIT_SUMCHECK
}TOF_ParserState;

typedef enum
{
    TOF_OFFLINE=0,
    TOF_READY,
    TOF_TESTTING
}TOF_status;

extern uint8_t TOF_STAUTS;
extern float TOF_height_cm;

uint8_t TOF_Init(void);
void TOF_DataAnlTask(uint8_t received_byte);
void TOF_DataUpdateTask(uint8_t dT_ms);


#endif //FLIGHT_CLION_NIZHOU_DRV_TOF_H
